import { reqChannelEidt, reqAllChannels } from '@/api/channel'
const state = {
  channels: [],
  AllChannels: []
}
const mutations = {
  setchannel(state, newChannels) {
    state.channels = newChannels
  },
  setAllChannels(state, newAllChannels) {
    state.AllChannels = newAllChannels
  },
  // 添加频道================
  addChannels(state, add) {
    state.channels.push(add)
  },
  // 删除频道============
  delChannels(state, delChannel) {
    state.channels = state.channels.filter(item => item.id !== delChannel.id)
  }
}
const actions = {
  async getChannelList(context) {
    const res = await reqChannelEidt()
    context.commit('setchannel', res.data.channels)
  },
  async getAllChannelsList(context) {
    const res = await reqAllChannels()
    context.commit('setAllChannels', res.data.channels)
  }
  // async getAddChannels(context) {
  //   const res = reqAddChannel()
  //   console.log(res)
  //   context.commit('setAllChannels', res.data.channels)
  // }
}
const getters = {
  optionChannels(state) {
    const result = state.AllChannels.filter(item => {
      const index = state.channels.findIndex(data => data.id === item.id)
      return index === -1
    })
    console.log(result)
    return result
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
